﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.ComponentModel;
namespace CoreData
{
    public class Product
    {

        //[Description("ID")]
        public long ID { get; set; }

        [Description("Mã hàng hóa")]
        public string Code { get; set; }
        [Description("Tên hàng hóa")]
        public string Name { get; set; }
        //[Description("Product_GroupID")]
        public long Product_GroupID { get; set; }
        // [Description("Product_ProviderID")]
        public long Product_ProviderID { get; set; }
        //[Description("Stock_UnitID")]
        public long Stock_UnitID { get; set; }
        //[Description("Output_UnitID")]
        public long Output_UnitID { get; set; }
        //[Description("Input_UnitID")]
        public long Input_UnitID { get; set; }
        [Description("Giá nhập")]
        public int Input_Price { get; set; }
        [Description("Giá bán")]
        public int Output_Price { get; set; }
        [Description("Mô tả")]
        public string Description { get; set; }
        [Description("Tồn kho tối thiếu")]
        public int Stock_Min { get; set; }
        [Description("Tồn kho tối đa")]
        public int Stock_Max { get; set; }
        [Description("Sử dụng")]
        public bool Active { get; set; }
        [Description("Nhóm hàng hóa")]
        public string ProductGroupExt { get; set; }
        [Description("Nhà cung cấp")]
        public string ProductProviderExt { get; set; }
        [Description("Đơn vị lưu trong kho")]
        public string StockUnitExt { get; set; }
        [Description("Đơn vị xuất kho")]
        public string OutPutUnitExt { get; set; }
        [Description("Đơn vị nhập kho")]
        public string UnitNameExt { get; set; }
        public decimal PriceExt { get; set; }
        public int InStockQuantityExt { get; set; }
        public int InputQuantityExt { get; set; }
        public int OutputQuantityExt { get; set; }
        public DateTime VoucherDateExt { get; set; }
        public string VoucherNoExt { get; set; }
        public string VoucherDescriptionExt { get; set; }
        [Description("...")]
        public bool SelectRowExt { get; set; }

        public Product()
        {
            Code = "";
            Name = "";
            Description = "";
            //  Stock_Max ="";   
        }

        static Product DynamicCast<T>(object row_data, object row_header) where T : Product
        {
            // row_data : DataRow
            // row_header : DataColumnCollection
            Product ret = new Product();
            DataRow dt = (DataRow)row_data;

            foreach (DataColumn column in (DataColumnCollection)row_header)
            {
                switch (column.ColumnName)
                {
                    case "ID":
                        ret.ID = ConvertObject.ToLong(dt[column]);
                        break;
                    case "Code":
                        ret.Code = ConvertObject.ToString(dt[column]);
                        break;
                    case "Name":
                        ret.Name = ConvertObject.ToString(dt[column]);
                        break;
                    case "Product_GroupID":
                        ret.Product_GroupID = ConvertObject.ToLong(dt[column]);
                        break;
                    case "Description":
                        ret.Description = ConvertObject.ToString(dt[column]);
                        break;
                    case "Stock_UnitID":
                        ret.Stock_UnitID = ConvertObject.ToLong(dt[column]);
                        break;
                    case "Output_UnitID":
                        ret.Output_UnitID = ConvertObject.ToLong(dt[column]);
                        break;
                    case "Input_UnitID":
                        ret.Input_UnitID = ConvertObject.ToLong(dt[column]);
                        break;
                    case "Stock_Min":
                        ret.Stock_Min = ConvertObject.ToInt(dt[column]);
                        break;
                    case "Stock_Max":
                        ret.Stock_Max = ConvertObject.ToInt(dt[column]);
                        break;
                    case "Output_Price":
                        ret.Output_Price = ConvertObject.ToInt(dt[column]);
                        break;
                    case "Input_Price":
                        ret.Input_Price = ConvertObject.ToInt(dt[column]);
                        break;
                    case "Active":
                        ret.Active = ConvertObject.ToBool(dt[column]);
                        break;
                    case "Product_ProviderID":
                        ret.Product_ProviderID = ConvertObject.ToLong(dt[column]);
                        break;

                    case "ProductGroup":
                        ret.ProductGroupExt = ConvertObject.ToString(dt[column]);
                        break;
                    case "ProductProvider":
                        ret.ProductProviderExt = ConvertObject.ToString(dt[column]);
                        break;
                    case "StockUnitName":
                        ret.StockUnitExt = ConvertObject.ToString(dt[column]);
                        break;
                    case "OutUnitName":
                        ret.OutPutUnitExt = ConvertObject.ToString(dt[column]);
                        break;
                    case "UnitName":
                        ret.UnitNameExt = ConvertObject.ToString(dt[column]);
                        break;
                    case "Price":
                        ret.PriceExt = ConvertObject.ToDecimal(dt[column]);
                        break;
                    case "InStockQuantity":
                        ret.InStockQuantityExt = ConvertObject.ToInt(dt[column]);
                        break;
                    case "OutputQuantity":
                        ret.OutputQuantityExt = ConvertObject.ToInt(dt[column]);
                        break;
                    case "InputQuantity":
                        ret.InputQuantityExt = ConvertObject.ToInt(dt[column]);
                        break;
                    case "VoucherDate":
                        ret.VoucherDateExt = ConvertObject.ToDateTime(dt[column]);
                        break;
                    case "VoucherNo":
                        ret.VoucherNoExt = ConvertObject.ToString(dt[column]);
                        break;
                    case "VoucherDescription":
                        ret.VoucherDescriptionExt = ConvertObject.ToString(dt[column]);
                        break;
                    default:
                        break;
                }
            }

            return ret;
        }

    }
}
